<template>
	<view class="container">
		<view class="search">
			<view class="search_box">
				<u-icon name="search" size="40" color="#707070"></u-icon>
				<input type="text" placeholder="搜索内容" v-model="title" />
				<view class="search_button" @click="searchClick">搜索</view>
			</view>
		</view>
		<!-- <view class="commodity_type">
			<view class="option">
				<view class="all" @click="allType = true">
					<view>全</view>
					<view>部</view>
					<u-icon name="list"></u-icon>
				</view>
				<view class="list" v-for="(item,index) in 5" :key="item" :class="typeCurrent==index?'active':''"
					@click="typeCurrent = index">
					<image src="https://img.js.design/assets/img/667d2c7c1e214b3e86c76048.png" mode=""></image>
					<view class="name">鸡肉</view>
				</view>
			</view>
		</view> -->
		<view class="goods_box">
			<view class="goods_list" v-for="(item,index) in goodsList" :key="index">
				<image :src="item.thumb"></image>
				<view class="goods_title">{{item.title}}</view>
				<view class="jiage">
					<text>{{item.score}}积分</text>
					<view class="btn">去兑换</view>
				</view>
			</view>
		</view>
		<view class="type_mask" v-if="allType">
			<view class="mask_content">
				<view class="list_box">
					<view class="list" v-for="(item,index) in 15" :key="index" :class="typeCurrent2==index?'active':''"
						@click="selectType(item,index)">
						<image src="https://img.js.design/assets/img/667d2c7c1e214b3e86c76048.png" mode=""></image>
						<view class="name">鸡肉</view>
					</view>
				</view>
				<view class="sq" @click="allType = false">点击收起<u-icon name="arrow-up"></u-icon></view>
			</view>
		</view>
		<u-loadmore :status="status" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				allType: false,
				typeCurrent: 0,
				goodsList: [],
				page: 1,
				pageSize: 10,
				total: 1,
				count: 1,
				title: '',
				status: 'loadmore',
			}
		},
		async onLoad() {
			await this.getData()
		},
		methods: {
			searchClick() {
				this.getData()
			},
			async getData() {
				await this.$allApi.getScoreGoodsList({
					page: this.page,
					pagesize: this.pageSize,
					title: this.title,
				}).then(res => {
					if (this.page == 1) {
						this.goodsList = res.data.data
						this.total = res.data.total
						this.count = Math.ceil(Number(this.total) / 10)
					} else {
						this.goodsList = [...this.goodsList, ...res.data.data]
					}
					if (this.page >= this.count) {
						this.status = 'nomore'
					} else {
						this.status = 'loadmore'
					}
				})
			},
		},
		onReachBottom() {
			if (this.page >= this.count) return this.status = 'nomore';
			this.status = 'loading';
			this.page = ++this.page;
			this.getData()
		},
	}
</script>

<style scoped lang="scss">
	.goods_box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex-wrap: wrap;
		padding: 20rpx;

		.goods_list {
			width: 346rpx;
			height: 452rpx;
			border-radius: 10rpx;
			background: rgba(255, 255, 255, 1);
			margin-bottom: 20rpx;

			.goods_title {
				font-size: 24rpx;
				padding: 0 20rpx;
			}

			.jiage {
				color: red;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 20rpx;

				.btn {
					width: 88rpx;
					height: 36rpx;
					border-radius: 24rpx;
					background: linear-gradient(90deg, rgba(142, 195, 0, 1) 0%, rgba(18, 134, 0, 1) 100%);
					color: #fff;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 20rpx;
				}
			}

			image {
				width: 346rpx;
				height: 320rpx;
				border-radius: 10rpx 10rpx 0rpx 0rpx;

			}
		}
	}

	.type_mask {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100vw;
		height: calc(100vh - 132rpx);
		z-index: 99;
		background: rgba(0, 0, 0, .5);

		.mask_content {
			background: #fff;
			padding: 30rpx;
			border-radius: 0 0 20rpx 20rpx;

			.sq {
				text-align: center;
				color: #999999;
				font-size: 24rpx;
			}

			.list_box {

				display: flex;
				align-items: center;
				justify-content: flex-start;
				flex-wrap: wrap;

				.list {

					width: 25%;
					font-size: 28rpx;
					text-align: center;
					margin-bottom: 20rpx;
					padding: 0 24rpx;
				}

				.name {
					border-radius: 28rpx;
					height: 52rpx;
					background: #fff;
					display: flex;
					align-items: center;
					justify-content: center;
					border: 2rpx solid #EDEDED;
				}

				image {
					width: 92rpx;
					height: 92rpx;
					border-radius: 46rpx;
					border: 2rpx solid #fff;
				}
			}

			.active {
				.name {
					height: 52rpx;
					border-radius: 28rpx;
					border: 2rpx solid #40AE36;
					color: #40AE36;
					display: flex;
					align-items: center;
					justify-content: center;

				}

				image {
					border: 2rpx solid #40AE36;
				}
			}
		}
	}

	.commodity_type {
		background: #fff;
		margin-top: 20rpx;
		padding: 20rpx;
		border-top: 1px solid #F3F3F3;
		padding: 30rpx;
		position: relative;
		border-bottom: 1px solid #F3F3F3;

		.all {
			position: absolute;
			right: 0;
			top: -2rpx;
			width: 64rpx;
			height: 202rpx;
			background: #FFFFFF;
			border: 2rpx solid #F2F2F2;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			text-align: center;
		}

		.option {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.list {
				font-size: 28rpx;
				text-align: center;
				flex: 1;

				.name {
					width: 130rpx;
					height: 52rpx;
					border-radius: 28rpx;
					background: #fff;
					display: flex;
					align-items: center;
					justify-content: center;
				}

				image {
					width: 92rpx;
					height: 92rpx;
					border-radius: 46rpx;
					border: 2rpx solid #fff;
				}
			}

			.active {
				.name {
					width: 130rpx;
					height: 52rpx;
					border-radius: 28rpx;
					background: #40AE36;
					color: #fff;
					display: flex;
					align-items: center;
					justify-content: center;

				}

				image {
					border: 2rpx solid #40AE36;
				}
			}

		}

	}

	.container {
		min-height: 100vh;
		background: #f8f8f8;
	}

	.search {
		background: #fff;
		padding: 20rpx 0;
		width: 100vw;
		height: 100rpx;
		position: sticky;
		display: flex;
		align-items: center;
		justify-content: center;
		left: 0;
		top: 0;
		z-index: 999;
	}

	.search_box {
		width: 710rpx;
		margin: 0 auto;
		height: 60rpx;
		border-radius: 30rpx;
		background: #FFFFFF;
		border: 2rpx solid #128600;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-left: 28rpx;
		padding-right: 4rpx;

		input {
			flex: 1;
			padding: 0 20rpx;
		}

		.search_button {
			width: 110rpx;
			height: 48rpx;
			border-radius: 24rpx;
			background: linear-gradient(90deg, #8EC300 0%, #128600 100%);
			display: flex;
			align-items: center;
			justify-content: center;
			color: #fff;
			font-size: 24rpx;
		}
	}
</style>